{{include './index_header.html' '注册'}}
<div class="mui-content">
    <div class="mui-card-content">
        <img src="./img/cbd.jpg" alt="">
    </div>
    <form class="mui-input-group">
        <div class="mui-input-row">
            <label>用户名</label>
        <input type="text" class="mui-input-clear" autocomplete="off"  placeholder="请输入用户名" name="name" id="name" required>
        </div>
        <div class="mui-input-row">
            <label>密码</label>
            <input type="password" class="mui-input-password" autocomplete="off"  placeholder="请输入密码" name="psw" required>
        </div>
        <div class="mui-button-row">
            <button type="submit" class="mui-btn mui-btn-success" id="register" >注册</button>
        </div>
    </form>
</div>

<script>
    var name = $.cookie('name')
    console.log(name);
    if(name && name != 'undefined'){
        $('#name').prop('readonly',true).val(name)
        $('#name').removeClass('mui-input-clear')
        $('.mui-btn').html('修改密码')
        $('form').submit(function(e){
            e.preventDefault()
            $.post('/user/alterPsw',$(this).serialize(),(data)=>{
                mui.alert(data.msg,'系统提示','确定',function(){
                    if(data.code == 1){
                        location.href = '/mine'
                    }
                })
            })
        })
    }else{
        $('form').submit(function(e){
            e.preventDefault()
            var info = $(this).serialize()
            $.post('/user/register',info,(data)=>{
                mui.alert(data.msg,'系统提示','确定',function(){
                    if(data.code == 1){
                        location.href = '/mine'
                    }
                })
            })
        })
    }
    
</script>
</body>
</html>